Developer Documentation

QuickTime 4 API Documentation
QuickTime Music Architecture

| Previous | Chapter Contents | Chapter Top | Next |

Tune Player Functions

This section describes the functions the tune player provides for setting, queueing, and manipulating music sequences. It also describes tune player utility functions.

TuneSetHeader

The TuneSetHeader function prepares the tune player to accept subsequent music event sequences by defining one or more parts to be used by sequence Note events.

pascal ComponentResult TuneSetHeader(
                     TunePlayer tp,
                     unsigned long *header);
tp
A tune player identifier, obtained from the Component Manager's OpenComponent function. See the chapter "Component Manager" in QuickTime 3 Reference for details.

header
A pointer to a list of instruments that will be used in subsequent calls to the TuneQueue function. The list can include note request General events with subtypes of kGeneralEventNoteRequest , kGeneralEventPartKey , kGeneralEventAtomicInstrument , kGeneralEventMIDIChannel , and kGeneralEventUsedNotes . It can also include atomic instruments. The list is terminated by a marker event of subtype end.

function result
A result code.

DISCUSSION

The TuneSetHeader function is the first QuickTime music architecture call to play a music sequence. The header parameter points to one or more initialized General events and atomic instruments. The event list pointed to by the header parameter must conclude with a marker event of subtype end.

Only one call to TuneSetHeader is required. Each TuneSetHeader call resets the tune player.

See ALSO

The TuneSetHeaderWithSize function [link] and the TuneSetNoteChannels function [link] .

TuneSetHeaderWithSize

The TuneSetHeaderWithSize function is like the TuneSetHeader function in that it prepares the tune player to accept subsequent music event sequences by defining one or more parts to be used by sequence Note events. But unlike the TuneSetHeader function, TuneSetHeaderWithSize allows you to specify the header length in bytes. This prevents the call from parsing off the end if the music event sequence is missing an end marker.

extern pascal ComponentResult TuneSetHeaderWithSize(
                     TunePlayer tp,
                     unsigned long *header,
                     unsigned long size);
tp
A tune player identifier, obtained from the Component Manager's OpenComponent function. See the chapter "Component Manager" in QuickTime 3 Reference for details.

header
A pointer to a list of instruments that will be used in subsequent calls to the TuneQueue function. The list can include General events with subtypes of kGeneralEventNoteRequest , kGeneralEventPartKey , kGeneralEventAtomicInstrument , kGeneralEventMIDIChannel , and kGeneralEventUsedNotes . It can also include atomic instruments. The list is terminated by a marker event of subtype end.

size
The size of the header in bytes.

See ALSO

The TuneSetHeader function [link] and the TuneSetNoteChannels function [link] .

TuneSetNoteChannels

You use the TuneSetNoteChannels function to assign note channels to a tune player.

extern pascal ComponentResult TuneSetNoteChannels(
                     TunePlayer tp,
                     unsigned long count,
                     NoteChannel *noteChannelList,
                     TunePlayCallBackUPP playCallBackProc,
                     long refCon);
tp
Specifies the instance of a tune player component for this operation. Your software obtains this reference when calling the Component Manager's OpenComponent or OpenDefaultComponent function. See the chapter "Component Manager" in QuickTime 3 Reference for details.

count
The number of note channels to assign.

noteChannelList
A pointer to the list of note channels to assign.

playCallBackProc
A pointer to a function in your software that is called for each event whose part number is greater than the value of the count parameter.

refCon
A reference constant that is passed to the function specified by the playCallBackProc parameter whenever it is called.

DISCUSSION

When you call TuneSetNoteChannels, any note channels that were previously assigned to the tune player are no longer used and are disposed of.

The parts for the note channels you assign are numbered from 1 to the value of the count parameter.

The playCallBackProc and refCon parameters let you to use the tune player as a general purpose timer/sequencer. The function in your software pointed to by the playCallBackProc parameter is called for each event whose part number is greater than the value of the count parameter. Events whose part numbers are less than or equal to the value of the count parameter are passed to the note channel rather than the callback procedure.

The playCallBackProc parameter must point to a function with the following prototype:

typedef pascal void (*TunePlayCallBackProcPtr)(
    unsigned long *event,
    long seed,
    long refCon);

The event parameter is a pointer to a QuickTime music event structure in the sequence data. The seed parameter is a 32-bit value that is guaranteed to be different for each call to the callback routine (unless 2^32 calls are made, after which the values repeat), with one exception: the value passed at the beginning of a note is also passed at the end of the note's duration, together with a note structure or an extended note in which the velocity bits are set to 0 . The refCon parameter is the reference constant that is passed to the TuneSetNoteChannels function.

TuneQueue

The TuneQueue function places a sequence of music events into a queue to be played.

pascal ComponentResult TuneQueue(
                     TunePlayer tp,
                     unsigned long *tune,
                     Fixed tuneRate,
                     unsigned long tuneStartPosition,
                     unsigned long tuneStopPosition,
                     unsigned long queueFlags,
                     TuneCallBackUPP callBackProc,
                     long refCon);
tp
A tune player identifier, obtained from the Component Manager's OpenComponent function. See the chapter "Component Manager" in QuickTime 3 Reference for details.

tune
Pointer to an array of events, terminated by a marker event of subtype end.

tuneRate
Fixed-point speed at which to play the sequence. "Normal" speed is 0x00010000 .

tuneStartPosition
Sequence starting time.

tuneStopPosition
Sequence ending time.

queueFlags
Flags with details about how to play the queued tunes. For valid values see "Tune Queue Flags" .

callBackProc
Points to your callback function. Your callback function must have the following form:

pascal void MyCallBackProc (QTCallBack cb, long refcon);

refcon
Contains a reference constant value. The Movie Toolbox passes this reference constant to your error-notification function each time it calls your function.

function result
A result code. In addition to QuickTime music architecture result codes, this function may return TimeBase result codes.

DISCUSSION

The tuneStartPosition and tuneStopPosition parameters specify, in time units numbered from zero for the beginning of the sequence, which part of the queued sequence to play. To play all of it, pass 0 and 0xFFFFFFFF, respectively.

If there is a sequence currently playing, the newly queued sequence begins as soon as the active sequence ends unless the queueFlags parameter is kTuneStartNow , in which case the currently playing sequence is immediately terminated and the new one started.

TuneStop

The TuneStop function stops a currently playing sequence.

pascal ComponentResult TuneStop(
                     TunePlayer tp,
                     long stopFlags);
tp
A tune player identifier, obtained from the Component Manager's OpenComponent function. See the chapter "Component Manager" in QuickTime 3 Reference for details.

stopFlags
Must be zero.

function result
A result code.

TuneGetVolume

The TuneGetVolume function returns the volume associated with the entire sequence.

pascal ComponentResult TuneGetVolume(
                     TunePlayer tp);
tp
A tune player identifier, obtained from the Component Manager's OpenComponent function. See the chapter "Component Manager" in QuickTime 3 Reference for details.

function result
The volume as a value from 0.0 to 1.0 or a negative result code.

TuneSetVolume

The TuneSetVolume function sets the volume for the entire sequence.

pascal ComponentResult TuneSetVolume(
                     TunePlayer tp,
                     Fixed volume);
tp
A tune player identifier, obtained from the Component Manager's OpenComponent function. See the chapter "Component Manager" in QuickTime 3 Reference for details.

volume
The volume to use for the sequence. The value is a fixed 16.16 number.

function result
A result code.

DISCUSSION

The TuneSetVolume function sets the volume level of the active sequence to the value of the volume parameter ranging from 0.0 to 1.0.

Individual instruments within the sequence can maintain independent volume levels.

TuneSetSoundLocalization

The TuneSetSoundLocalization function passes sound localization data to a tune player.

extern pascal ComponentResult TuneSetSoundLocalization(
                     TunePlayer tp,
                     Handle data);
tp
A tune player identifier, obtained from the Component Manager's OpenComponent function. See the chapter "Component Manager" in QuickTime 3 Reference for details.

data
The sound localization data to be passed.

function result
A result code.

TuneGetTimeBase

The TuneGetTimeBase function returns the time base of the tune player.

pascal ComponentResult TuneGetTimeBase(
                     TunePlayer tp,
                     TimeBase *tb);
tp
A tune player identifier, obtained from the Component Manager's OpenComponent function. See the chapter "Component Manager" in QuickTime 3 Reference for details.

tb
An initialized TimeBase object.

function result
A result code.

DISCUSSION

The TuneGetTimeBase function returns, in the tb parameter, the time base used to control the sequence timing. The sequence can be controlled in several ways through its time base. The rate of playback can be changed, or the TimeBase object can be slaved to a clock or time base different than real time.

TuneGetTimeScale

The TuneGetTimeScale function returns the current time scale, in units-per-second, for the specified tune player instance.

pascal ComponentResult TuneGetTimeScale(
                     TunePlayer tp,
                     TimeScale *scale);
tp
A tune player identifier, obtained from the Component Manager's OpenComponent function. See the chapter "Component Manager" in QuickTime 3 Reference for details.

scale
An initialized TimeScale object.

function result
A result code.

TuneSetTimeScale

The TuneSetTimeScale function sets the time scale used by the specified tune player instance.

pascal ComponentResult TuneSetTimeScale(
                     TunePlayer tp,
                     TimeScale scale);
tp
A tune player identifier, obtained from the Component Manager's OpenComponent function. See the chapter "Component Manager" in QuickTime 3 Reference for details.

scale
The time scale value to be used, in units per second.

function result
A result code.

DISCUSSION

The TuneSetTimeScale function sets the time scale data used by the tune player's sequence data when interpreting time-based events.

TuneGetPartMix

You use the TuneGetPartMix function to get volume, balance, and mixing settings for a specified part of a tune.

pascal ComponentResult TuneGetPartMix (
                     TunePlayer tp,
                     unsigned long partNumber,
                     long *volumeOut,
                     long *balanceOut,
                     long *mixFlagsOut);
tp
A tune player identifier, obtained from the Component Manager's OpenComponent function. See the chapter "Component Manager" in QuickTime 3 Reference for details.

partNumber
Specifies the part number for this request.

volumeOut
Returns the volume for this part.

balanceOut
Returns the balance for the part.

mixFlagsOut
Returns the flags that control part mixing.

TuneSetPartMix

You use the TuneGetPartMix function to set volume, balance, and mixing settings for a specified part of a tune.

pascal ComponentResult TuneSetPartMix (
                     TunePlayer tp,
                     unsigned long partNumber,
                     long *volume,
                     long *balance,
                     long *mixFlags);
tp
A tune player identifier, obtained from the Component Manager's OpenComponent function. See the chapter "Component Manager" in QuickTime 3 Reference for details.

partNumber
Specifies the part number for this request.

volume
Specifies the volume for this part.

balance
Specifies the balance for the part.

mixFlags
Specifies the flags that control part mixing.

TuneInstant

You can use the TuneInstant function to play the particular sequence events active at a specified position.

pascal ComponentResult TuneInstant(
                     TunePlayer tp,
                     unsigned long *tune,
                     unsigned long tunePosition);
tp
A tune player identifier, obtained from the Component Manager's OpenComponent function. See the chapter "Component Manager" in QuickTime 3 Reference for details.

tune
Pointer to tune sequence data.

tunePosition
Position within tune sequence data in time units.

function result
A result code.

DISCUSSION

The TuneInstant function plays the notes that are "on" at the point specified by the tunePosition parameter. The notes are started and then left playing on return. The notes can be silenced by calling the TuneStop function. This call is useful for enabling user "scrubbing" on a sequence.

TunePreroll

The TunePreroll function prepares for playing tune player sequence data by attempting to reserve note channels for each part in the sequence.

pascal ComponentResult TunePreroll (TunePlayer tp);
tp
A tune player identifier, obtained from the Component Manager's OpenComponent function. See the chapter "Component Manager" for details.

function result
A result code.

TuneUnroll

The TuneUnroll function releases any note channel resources that may have been locked down by previous calls to TunePreroll for this tune player.

pascal ComponentResult TuneUnroll (TunePlayer tp);
tp
A tune player identifier, obtained from the Component Manager's OpenComponent function. See the chapter "Component Manager" in QuickTime 3 Reference for details.

function result
A result code.

TuneGetIndexedNoteChannel

You can use the TuneGetIndexedNoteChannel function to determine how many parts the tune is playing and which instrument is assigned to those parts.

pascal ComponentResult TuneGetIndexedNoteChannel(
                     TunePlayer tp,
                     long i,
                     NoteChannel *nc);
tp
A tune player identifier, obtained from the Component Manager's OpenComponent function. See the chapter "Component Manager" for details.

i
Note channel index or 0 to get the number of parts.

nc
Allocated initialized note channel.

function result
A positive value is the number of note channels used by the tune player; a negative value is A result code.

DISCUSSION

The tune player allocates note channels that best satisfy the requested instrument in the tune header. The application can use this call to determine which instrument was actually used for each note channel. The TuneGetIndexedNoteChannel function takes the tune player in the tp parameter and returns the number of parts (1...n) allocated to the tune player. You can then pass the function a part index and it returns, in the nc parameter, the note channel allocated for that part.

TuneGetStatus

The TuneGetStatus function returns an initialized structure describing the state of the tune player instance.

pascal ComponentResult TuneGetStatus(
                     TunePlayer tp,
                     TuneStatus *status);
tp
A tune player identifier, obtained from the Component Manager's OpenComponent function. See the chapter "Component Manager" in QuickTime 3 Reference for details.

status
A pointer to an initialized tune status structure [link] .

function result
A result code.

TuneSetPartTranspose

The TuneSetPartTranspose function modifies the pitch and volume of every note of a tune.

extern pascal ComponentResult TuneSetPartTranspose(
                     TunePlayer tp,
                     unsigned long part,
                     long transpose,
                     long velocityShift);
tp
A tune player identifier, obtained from the Component Manager's OpenComponent function. See the chapter "Component Manager" for details.

part
The part for which you want to change pitch and volume.

transpose
A value by which to modify the pitch of the note. The value is a small integer for semitones or an 8.8 fixed-point number for microtones.

velocityShift
A value to add to the velocity parameter passed to the NAPlayNote function.

function result
A result code.

TuneGetNoteAllocator

The TuneGetNoteAllocator function returns the instance of the note allocator that the tune player is using.

extern pascal NoteAllocator TuneGetNoteAllocator (TunePlayer tp);
tp
A tune player identifier, obtained from the Component Manager's OpenComponent function. See the chapter "Component Manager" in QuickTime 3 Reference for details.

function result
A note allocator or A result code.

TuneSetSofter

The TuneSetSofter function adjusts the volume a tune is played at to the softer volume produced by QuickTime 2.1. Files imported with QuickTime 2.1 automatically played softer. Files imported with QuickTime 2.5 or later play at the new, louder volume.

extern pascal ComponentResult TuneSetSofter(
                     TunePlayer tp,
                     long softer);
tp
A tune player identifier, obtained from the Component Manager's OpenComponent function. See the chapter "Component Manager" for details.

softer
A value of 1 means play at the QuickTime 2.1 volume; a value of 0 means don't make the volume softer.

function result
A result code.

TuneSetBalance

Use the TuneSetBalance function to modify the pan controller setting for a tune player.

extern pascal ComponentResult TuneSetBalance(
                     TunePlayer tp,
                     long balance);
tp
A tune player identifier, obtained from the Component Manager's OpenComponent function. See the chapter "Component Manager" in QuickTime 3 Reference for details.

balance
Modifies the pan controller setting. Valid values are from -128 to 128 for left to right balance.

function result
A result code.

TuneTask

Call the TuneTask function periodically to allow a tune player to perform tasks it must perform at foreground task time.

extern pascal ComponentResult TuneTask (TunePlayer tp);
tp
A tune player identifier, obtained from the Component Manager's OpenComponent function. See the chapter "Component Manager" in QuickTime 3 Reference for details.

function result
A result code.

DISCUSSION

Certain operations can be performed only at foreground application task time. Specifically, the QuickTime music synthesizer cannot load instruments from disk at interrupt time. As a result, embedded program changes are not performed until TuneTask is called.


© 1999 Apple Computer, Inc.

| Previous | Chapter Contents | Chapter Top | Next |